﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace LogoScriptIDE
{
    /// <summary>
    /// OptionWindow.xaml 的交互逻辑
    /// </summary>
    public partial class OptionWindow : Window
    {
        #region Initialization

        /// <summary>
        /// 构造函数
        /// </summary>
        public OptionWindow()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 文字大小下拉框内容生成队列
        /// </summary>
        private List<int> TextSizeArr()
        {
            List<int> myList = new List<int>();
            for (int i = 8; i <= 30; i++)
            {
                myList.Add(i);
            }
            return myList;
        }

        /// <summary>
        /// 缩进大小下拉框内容生成队列
        /// </summary>
        private List<int> IndentionSizeArr()
        {
            List<int> myList = new List<int>();
            for (int i = 1; i <= 8; i++)
            {
                myList.Add(i);
            }
            return myList;
        }

        /// <summary>
        /// 颜色设置下拉框内容生成队列
        /// </summary>
        private List<string> ColorSettingArr()
        {
            List<string> myList = new List<string>();
            myList.Add("BackGround");
            myList.Add("BreakPoint");
            myList.Add("CurrentLine");
            myList.Add("ErrorLine");
            myList.Add("LineNumber");
            myList.Add("PauseArrow");
            myList.Add("PauseLine");
            myList.Add("StackLine");
            return myList;
        }

        /// <summary>
        /// 高亮内容选择下拉框内容生成队列
        /// </summary>
        private List<string> HighLightSettingArr()
        {
            List<string> myList = new List<string>();
            myList.Add("Comment");
            myList.Add("String");
            myList.Add("KeyWord");
            myList.Add("Function");
            myList.Add("Digit");
            return myList;
        }

        /// <summary>
        /// 预置样式下拉框内容生成队列
        /// </summary>
        /// <returns></returns>
        private List<string> StyleArr()
        {
            List<string> myList = new List<string>();
            myList.Add("Custom");
            myList.Add("Default");
            myList.Add("Pascal");
            myList.Add("Desert");
            return myList;
        }

        /// <summary>
        /// 载入窗口
        /// </summary>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //Option Window中各下拉框内容加载
            ui_TextSize.ItemsSource = TextSizeArr();
            ui_IndentionSize.ItemsSource = IndentionSizeArr();
            ui_TextFont.ItemsSource = Fonts.SystemFontFamilies.OrderBy(m => m.ToString());
            ui_ColorSettingSelected.ItemsSource = ColorSettingArr();
            ui_HighlightSetting.ItemsSource = HighLightSettingArr();
            ui_style.ItemsSource = StyleArr();

            //各下拉框初始选定值
            ui_ColorSettingSelected.SelectedIndex = 0;
            ui_HighlightSetting.SelectedIndex = 0;
            
            //Option window中各项初始值设置
            SelectedItemChanged(myconfig);
            InitializeStyle();
            
            ui_style.SelectedIndex = 0;
        }
        /// <summary>
        /// 默认的样式
        /// </summary>
        private EditorWindow.Config defaultConfig = new EditorWindow.Config();
        
        /// <summary>
        /// 用户上次关闭时留下的自定义样式
        /// </summary>
        public EditorWindow.Config myconfig = new EditorWindow.Config();
        
        /// <summary>
        /// pascal样式
        /// </summary>
        private EditorWindow.Config pascalStyleConfig = new EditorWindow.Config();
        
        /// <summary>
        /// desert样式
        /// </summary>
        private EditorWindow.Config desertStyleConfig = new EditorWindow.Config();

        /// <summary>
        /// 载入EditorWindow中已存在的默认样式
        /// </summary>
        public void LoadDefaultConfig(EditorWindow.Config config)
        {
            defaultConfig = config;
        }

        /// <summary>
        /// 载入用户上次关闭时留下的自定义样式
        /// </summary>
        public void LoadConfig(EditorWindow.Config config)
        {
            myconfig = config;
        }

        /// <summary>
        /// 预置的pascal,dessert的样式设置
        /// </summary>
        private void InitializeStyle()
        {
            pascalStyleConfig.BackGroundColor = Colors.DarkBlue;
            pascalStyleConfig.BreakpointColor = Colors.Red;
            pascalStyleConfig.ErrorLineColor = Colors.Red;
            pascalStyleConfig.LineNumberColor = Colors.LightSkyBlue;
            pascalStyleConfig.PauseArrowColor = Colors.White;
            pascalStyleConfig.PauseLineColor = Colors.DarkSeaGreen;
            pascalStyleConfig.CurrentLineColor = Color.FromArgb(128, 255, 255, 255);
            pascalStyleConfig.ShowLineNumber = true;
            pascalStyleConfig.TextColor = Colors.Yellow;
            pascalStyleConfig.TextFont = "Lucida Console";
            pascalStyleConfig.IndentionSize = 4;
            pascalStyleConfig.StackLineColor = Colors.PaleGreen;
            pascalStyleConfig.TextSize = 16;
            pascalStyleConfig.TextStyle = FontStyles.Normal;
            pascalStyleConfig.TextWeight = FontWeights.Normal;
            pascalStyleConfig.HighlightSettings["LogoScriptKeyWords"] = new EditorWindow.Config.Highlight(Colors.White, false, false);
            pascalStyleConfig.HighlightSettings["LogoScriptGlobalFunctions"] = new EditorWindow.Config.Highlight(Colors.Green, false, false);
            pascalStyleConfig.HighlightSettings["Digits"] = new EditorWindow.Config.Highlight(Colors.Cyan, false, false);
            pascalStyleConfig.HighlightSettings["Comment"] = new EditorWindow.Config.Highlight(Colors.Silver, false, false);
            pascalStyleConfig.HighlightSettings["String"] = new EditorWindow.Config.Highlight(Colors.LightBlue, false, false);

            desertStyleConfig.BackGroundColor = Color.FromArgb(255, 67, 67, 67);
            desertStyleConfig.BreakpointColor = Colors.DarkRed;
            desertStyleConfig.ErrorLineColor = Color.FromArgb(64, 255, 0, 0);
            desertStyleConfig.LineNumberColor = Colors.AntiqueWhite;
            desertStyleConfig.PauseArrowColor = Colors.White;
            desertStyleConfig.PauseLineColor = Color.FromArgb(64, 255, 255, 0);
            desertStyleConfig.CurrentLineColor = Color.FromArgb(128, 255, 255, 255);
            desertStyleConfig.ShowLineNumber = true;
            desertStyleConfig.TextColor = Colors.White;
            desertStyleConfig.TextFont = "Courier New";
            desertStyleConfig.IndentionSize = 4;
            desertStyleConfig.StackLineColor = Colors.PaleGreen;
            desertStyleConfig.TextSize = 16;
            desertStyleConfig.TextStyle = FontStyles.Normal;
            desertStyleConfig.TextWeight = FontWeights.Normal;
            desertStyleConfig.HighlightSettings["LogoScriptKeyWords"] = new EditorWindow.Config.Highlight(Color.FromArgb(255, 225, 225, 0), false, true);
            desertStyleConfig.HighlightSettings["LogoScriptGlobalFunctions"] = new EditorWindow.Config.Highlight(Color.FromArgb(255, 225, 128, 0), false, true);
            desertStyleConfig.HighlightSettings["Digits"] = new EditorWindow.Config.Highlight(Colors.Red, false, false);
            desertStyleConfig.HighlightSettings["Comment"] = new EditorWindow.Config.Highlight(Colors.SkyBlue, false, false);
            desertStyleConfig.HighlightSettings["String"] = new EditorWindow.Config.Highlight(Colors.Red, false, false);
        }

        #endregion

        #region TemporaryMember

        // 各颜色的临时储存
        // 用户在颜色对话框中修改颜色后，未应用前相应颜色暂时保存在以下变量中
        private Color tem_BackGroundColor = new Color();
        private Color tem_BreakPointColor = new Color();
        private Color tem_CurrentLineColor = new Color();
        private Color tem_ErrorLineColor = new Color();
        private Color tem_LineNumberColor = new Color();
        private Color tem_PauseArrowColor = new Color();
        private Color tem_PauseLineColor = new Color();
        private Color tem_StackLineColor = new Color();
        private Color tem_TextColor = new Color();

        // 各高亮设置的临时储存
        // 用户在高亮模块修改各分项属性后，未应用前相应高亮配置暂时保存在以下变量中
        private EditorWindow.Config.Highlight tem_CommentHighLight = new EditorWindow.Config.Highlight();
        private EditorWindow.Config.Highlight tem_StringHighLight = new EditorWindow.Config.Highlight();
        private EditorWindow.Config.Highlight tem_KeyWordHighLight = new EditorWindow.Config.Highlight();
        private EditorWindow.Config.Highlight tem_KeyFuncHighLight = new EditorWindow.Config.Highlight();
        private EditorWindow.Config.Highlight tem_DigitHighLight = new EditorWindow.Config.Highlight();

        /// <summary>
        /// 是否应用标记。用户单击apply，该标记被置为true
        /// </summary>
        public bool updateflag = false;

        #endregion

        #region InterfaceSelectionChanged

        /// <summary>
        /// Option Window上的所有控件显示根据当前传入的配置进行更改
        /// </summary>
        /// <param name="config">编辑器配置</param>
        private void SelectedItemChanged(EditorWindow.Config config)
        {
            
            //当前各控件显示情况根据配置文件更改
            ui_TextSize.SelectedItem = TextSizeArr().Where(m => m.ToString() == config.TextSize.ToString()).Single();
            ui_TextFont.SelectedItem = Fonts.SystemFontFamilies.Where(m => m.ToString().ToLower() == config.TextFont.ToLower()).Single();
            ui_IndentionSize.SelectedItem = IndentionSizeArr().Where(m => m.ToString() == config.IndentionSize.ToString()).Single();
            ui_ShowLineNumber.IsChecked = config.ShowLineNumber;
            ui_TextItalic.IsChecked = ItalicToBool(config.TextStyle);
            ui_TextBold.IsChecked = BoldToBool(config.TextWeight);

            //文字效果预览框根据配置文件更改
            TestLabel.FontFamily = ui_TextFont.SelectedItem as FontFamily;
            TestLabel.FontSize = double.Parse(ui_TextSize.SelectedItem.ToString());
            TestLabel.FontStyle = BoolToItalic((bool)ui_TextItalic.IsChecked);
            TestLabel.FontWeight = BoolToBold((bool)ui_TextBold.IsChecked);
            TestLabel.Foreground = ColorToBrush(config.TextColor);

            //各临时储存器根据配置文件发生更改
            tem_BackGroundColor = config.BackGroundColor;
            tem_BreakPointColor = config.BreakpointColor;
            tem_CurrentLineColor = config.CurrentLineColor;
            tem_ErrorLineColor = config.ErrorLineColor;
            tem_LineNumberColor = config.LineNumberColor;
            tem_PauseArrowColor = config.PauseArrowColor;
            tem_PauseLineColor = config.PauseLineColor;
            tem_StackLineColor = config.StackLineColor;
            tem_CommentHighLight = config.HighlightSettings["Comment"];
            tem_StringHighLight = config.HighlightSettings["String"];
            tem_KeyFuncHighLight = config.HighlightSettings["LogoScriptGlobalFunctions"];
            tem_KeyWordHighLight = config.HighlightSettings["LogoScriptKeyWords"];
            tem_DigitHighLight = config.HighlightSettings["Digits"];


            ui_TextColorPreview.Fill = ColorToBrush(config.TextColor);
            tem_TextColor = config.TextColor;

            //将当前下拉框中选中的内容参照临时储存器中的值进行修改控件
            SelectedItemToColorPreview();
            SelectedItemToHSPreview();
        }

        /// <summary>
        /// 文字效果预览框随着用户的修改展示预览效果
        /// </summary>
        private void ui_TextFont_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            TestLabel.FontFamily = ui_TextFont.SelectedItem as FontFamily;
            //将配置样式的值置为Custom
            ui_style.SelectedIndex = 0;
        }

        private void ui_TextSize_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            TestLabel.FontSize = double.Parse(ui_TextSize.SelectedItem.ToString());
            ui_style.SelectedIndex = 0;
        }

        private void ui_TextItalic_Click(object sender, RoutedEventArgs e)
        {
            TestLabel.FontStyle = BoolToItalic((bool)ui_TextItalic.IsChecked);
            ui_style.SelectedIndex = 0;
        }

        private void ui_TextBold_Click(object sender, RoutedEventArgs e)
        {
            TestLabel.FontWeight = BoolToBold((bool)ui_TextBold.IsChecked);
            ui_style.SelectedIndex = 0;
        }

        /// <summary>
        /// 下拉框修改后刷新后面的控件内容
        /// </summary>
        private void ui_ColorSettingSelected_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SelectedItemToColorPreview();
        }

        private void ui_HighlightSetting_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SelectedItemToHSPreview();
        }

        /// <summary>
        /// 修改属性后，自动修改样式下拉框为Custom
        /// </summary>
        private void ui_IndentionSize_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ui_style.SelectedIndex = 0;
        }

        private void ui_ShowLineNumber_Click(object sender, RoutedEventArgs e)
        {
            ui_style.SelectedIndex = 0;
        }

        /// <summary>
        /// 修改样式下拉框中的选中项后，刷新控件及临时储存器的值
        /// </summary>
        private void ui_style_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int item = ui_style.SelectedIndex;
            switch (ui_style.SelectedValue.ToString())
            {
                case "Default":
                    SelectedItemChanged(defaultConfig);
                    break;
                case "Pascal":
                    SelectedItemChanged(pascalStyleConfig);
                    break;
                case "Desert":
                    SelectedItemChanged(desertStyleConfig);
                    break;
                default: break;
            }
            ui_style.SelectedIndex = item;
        }
        
        #endregion

        #region TransFunction

        /// <summary>
        /// 格式转换函数，以配合各控件格式要求进行格式转换
        /// </summary>
        /// <param name="color">待转换格式</param>
        /// <returns>目标格式</returns>
        private Brush ColorToBrush(Color color)
        {
            Brush brush = new SolidColorBrush(color);
            return brush;
        }

        private bool ItalicToBool(FontStyle e)
        {
            if (e == FontStyles.Normal) return false;
            else return true;
        }

        private FontStyle BoolToItalic(bool e)
        {
            if (e) return FontStyles.Italic;
            else return FontStyles.Normal;
        }

        private bool BoldToBool(FontWeight e)
        {
            if (e == FontWeights.Normal) return false;
            else return true;
        }

        private FontWeight BoolToBold(bool e)
        {
            if (e) return FontWeights.Bold;
            else return FontWeights.Normal;
        }

        /// <summary>
        /// 将颜色对话框的返回值转换为Color类型
        /// </summary>
        private Color TransColorDialogResult(System.Windows.Forms.ColorDialog colorDialog)
        {
            Color color = new Color();
            color.R = colorDialog.Color.R;
            color.G = colorDialog.Color.G;
            color.B = colorDialog.Color.B;
            color.A = colorDialog.Color.A;
            return color;
        }

        /// <summary>
        /// 按照颜色选项下拉框的修改内容刷新后面的控件内容
        /// </summary>
        private void SelectedItemToColorPreview()
        {
            switch (ui_ColorSettingSelected.SelectedItem.ToString())
            {
                case "BackGround":
                    ui_ColorPreview.Fill = ColorToBrush(tem_BackGroundColor);
                    break;
                case "BreakPoint":
                    ui_ColorPreview.Fill = ColorToBrush(tem_BreakPointColor);
                    break;
                case "CurrentLine":
                    ui_ColorPreview.Fill = ColorToBrush(tem_CurrentLineColor);
                    break;
                case "ErrorLine":
                    ui_ColorPreview.Fill = ColorToBrush(tem_ErrorLineColor);
                    break;
                case "LineNumber":
                    ui_ColorPreview.Fill = ColorToBrush(tem_LineNumberColor);
                    break;
                case "PauseArrow":
                    ui_ColorPreview.Fill = ColorToBrush(tem_PauseArrowColor);
                    break;
                case "PauseLine":
                    ui_ColorPreview.Fill = ColorToBrush(tem_PauseLineColor);
                    break;
                case "StackLine":
                    ui_ColorPreview.Fill = ColorToBrush(tem_StackLineColor);
                    break;
                default: break;
            }
        }
        
        /// <summary>
        /// 按照传入的内容刷新后面的空间内容
        /// </summary>
        private void HSAssignment(Color color, bool bold, bool italic)
        {
            ui_HighLightColor.Fill = ColorToBrush(color);
            ui_HighLightBold.IsChecked = bold;
            ui_HighLightItalic.IsChecked = italic;
        }

        /// <summary>
        /// 按照高亮选项下拉框的修改内容刷新后面的控件内容
        /// </summary>
        private void SelectedItemToHSPreview()
        {
            switch (ui_HighlightSetting.SelectedItem.ToString())
            {
                case "Comment":
                    HSAssignment(tem_CommentHighLight.Color, tem_CommentHighLight.Bold, tem_CommentHighLight.Italic);
                    break;
                case "String":
                    HSAssignment(tem_StringHighLight.Color, tem_StringHighLight.Bold, tem_StringHighLight.Italic);
                    break;
                case "KeyWord":
                    HSAssignment(tem_KeyWordHighLight.Color, tem_KeyWordHighLight.Bold, tem_KeyWordHighLight.Italic);
                    break;
                case "Function":
                    HSAssignment(tem_KeyFuncHighLight.Color, tem_KeyFuncHighLight.Bold, tem_KeyFuncHighLight.Italic);
                    break;
                case "Digit":
                    HSAssignment(tem_DigitHighLight.Color, tem_DigitHighLight.Bold, tem_DigitHighLight.Italic);
                    break;
                default: break;
            }
        }

        #endregion

        #region ButtonClick

        /// <summary>
        /// 单击文字颜色设置按钮执行的动作
        /// </summary>
        private void ui_TextColorPreview_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            System.Windows.Forms.ColorDialog colorDialog = new System.Windows.Forms.ColorDialog();
            if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                tem_TextColor = TransColorDialogResult(colorDialog);
                ui_TextColorPreview.Fill = ColorToBrush(tem_TextColor);
                TestLabel.Foreground = ColorToBrush(tem_TextColor);
                ui_style.SelectedIndex = 0;
            }
        }

        /// <summary>
        /// 单击应用按钮执行的动作
        /// </summary>
        private void ApplyButton_Click(object sender, RoutedEventArgs e)
        {
            //无临时储存器的选项收集当前窗口中各控件的状态得到用户的选择结果
            myconfig.TextSize = int.Parse(ui_TextSize.SelectedValue.ToString());
            myconfig.TextFont = ui_TextFont.SelectedItem.ToString();
            myconfig.IndentionSize = int.Parse(ui_IndentionSize.SelectedItem.ToString());
            myconfig.ShowLineNumber = (bool)ui_ShowLineNumber.IsChecked;
            myconfig.TextStyle = BoolToItalic((bool)ui_TextItalic.IsChecked);
            myconfig.TextWeight = BoolToBold((bool)ui_TextBold.IsChecked);
            //有临时储存器的选项调用储存器的值得到用户的选择结果
            myconfig.BackGroundColor = tem_BackGroundColor;
            myconfig.BreakpointColor = tem_BreakPointColor;
            myconfig.CurrentLineColor = tem_CurrentLineColor;
            myconfig.ErrorLineColor = tem_ErrorLineColor;
            myconfig.LineNumberColor = tem_LineNumberColor;
            myconfig.PauseArrowColor = tem_PauseArrowColor;
            myconfig.PauseLineColor = tem_PauseLineColor;
            myconfig.StackLineColor = tem_StackLineColor;
            myconfig.TextColor = tem_TextColor;
            myconfig.HighlightSettings["Comment"] = tem_CommentHighLight;
            myconfig.HighlightSettings["String"] = tem_StringHighLight;
            myconfig.HighlightSettings["LogoScriptKeyWords"] = tem_KeyWordHighLight;
            myconfig.HighlightSettings["LogoScriptGlobalFunctions"] = tem_KeyFuncHighLight;
            myconfig.HighlightSettings["Digits"] = tem_DigitHighLight;
            //配置更改标记被置为已更改
            updateflag = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            Hide();
        }

        /// <summary>
        /// 场景颜色设置按钮的单击动作
        /// 根据当前场景颜色下拉框的选择内容来确定将参数传给哪个储存器，并刷新控件
        /// </summary>
        private void ui_ColorPreview_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            System.Windows.Forms.ColorDialog colorDialog = new System.Windows.Forms.ColorDialog();
            if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                switch (ui_ColorSettingSelected.SelectedItem.ToString())
                {
                    case "BackGround":
                        tem_BackGroundColor = TransColorDialogResult(colorDialog);
                        ui_ColorPreview.Fill = ColorToBrush(tem_BackGroundColor);
                        break;
                    case "BreakPoint":
                        tem_BreakPointColor = TransColorDialogResult(colorDialog);
                        ui_ColorPreview.Fill = ColorToBrush(tem_BreakPointColor);
                        break;
                    case "CurrentLine":
                        tem_CurrentLineColor = TransColorDialogResult(colorDialog);
                        ui_ColorPreview.Fill = ColorToBrush(tem_CurrentLineColor);
                        tem_CurrentLineColor.A = 96;
                        break;
                    case "ErrorLine":
                        tem_ErrorLineColor = TransColorDialogResult(colorDialog);
                        ui_ColorPreview.Fill = ColorToBrush(tem_ErrorLineColor);
                        tem_ErrorLineColor.A = 96;
                        break;
                    case "LineNumber":
                        tem_LineNumberColor = TransColorDialogResult(colorDialog);
                        ui_ColorPreview.Fill = ColorToBrush(tem_LineNumberColor);
                        break;
                    case "PauseArrow":
                        tem_PauseArrowColor = TransColorDialogResult(colorDialog);
                        ui_ColorPreview.Fill = ColorToBrush(tem_PauseArrowColor);
                        break;
                    case "PauseLine":
                        tem_PauseLineColor = TransColorDialogResult(colorDialog);
                        ui_ColorPreview.Fill = ColorToBrush(tem_PauseLineColor);
                        tem_PauseLineColor.A = 96;
                        break;
                    case "StackLine":
                        tem_StackLineColor = TransColorDialogResult(colorDialog);
                        ui_ColorPreview.Fill = ColorToBrush(tem_StackLineColor);
                        tem_StackLineColor.A = 96;
                        break;
                    default: break;
                }
                ui_style.SelectedIndex = 0;
            }
        }

        /// <summary>
        /// 高亮颜色设置按钮的单击动作
        /// 根据当前高亮设置下拉框的选择内容来确定将参数传给哪个储存器，并刷新控件
        /// </summary>
        private void ui_HighLightColor_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            System.Windows.Forms.ColorDialog colorDialog = new System.Windows.Forms.ColorDialog();
            if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                switch (ui_HighlightSetting.SelectedItem.ToString())
                {
                    case "Comment":
                        tem_CommentHighLight.Color = TransColorDialogResult(colorDialog);
                        break;
                    case "String":
                        tem_StringHighLight.Color = TransColorDialogResult(colorDialog);
                        break;
                    case "KeyWord":
                        tem_KeyWordHighLight.Color = TransColorDialogResult(colorDialog);
                        break;
                    case "Function":
                        tem_KeyFuncHighLight.Color = TransColorDialogResult(colorDialog);
                        break;
                    case "Digit":
                        tem_DigitHighLight.Color = TransColorDialogResult(colorDialog);
                        break;
                    default: break;
                }
                ui_style.SelectedIndex = 0;
            }
            //根据选择刷新旁边的相应控件
            SelectedItemToHSPreview();
        }

        /// <summary>
        /// 高亮斜体设置复选框的单击动作
        /// 根据当前高亮设置下拉框的选择内容来确定将参数传给哪个储存器，并刷新控件
        /// </summary>
        private void ui_HighLightItalic_Click(object sender, RoutedEventArgs e)
        {
            switch (ui_HighlightSetting.SelectedItem.ToString())
            {
                case "Comment":
                    tem_CommentHighLight.Italic = (bool)ui_HighLightItalic.IsChecked;
                    break;
                case "String":
                    tem_StringHighLight.Italic = (bool)ui_HighLightItalic.IsChecked;
                    break;
                case "KeyWord":
                    tem_KeyWordHighLight.Italic = (bool)ui_HighLightItalic.IsChecked;
                    break;
                case "Function":
                    tem_KeyFuncHighLight.Italic = (bool)ui_HighLightItalic.IsChecked;
                    break;
                case "Digit":
                    tem_DigitHighLight.Italic = (bool)ui_HighLightItalic.IsChecked;
                    break;
                default: break;
            }
            ui_style.SelectedIndex = 0;
        }

        /// <summary>
        /// 高亮粗体设置复选框的单击动作
        /// 根据当前高亮设置下拉框的选择内容来确定将参数传给哪个储存器，并刷新控件
        /// </summary>
        private void ui_HighLightBold_Click(object sender, RoutedEventArgs e)
        {
            switch (ui_HighlightSetting.SelectedItem.ToString())
            {
                case "Comment":
                    tem_CommentHighLight.Bold = (bool)ui_HighLightBold.IsChecked;
                    break;
                case "String":
                    tem_StringHighLight.Bold = (bool)ui_HighLightBold.IsChecked;
                    break;
                case "KeyWord":
                    tem_KeyWordHighLight.Bold = (bool)ui_HighLightBold.IsChecked;
                    break;
                case "Function":
                    tem_KeyFuncHighLight.Bold = (bool)ui_HighLightBold.IsChecked;
                    break;
                case "Digit":
                    tem_DigitHighLight.Bold = (bool)ui_HighLightBold.IsChecked;
                    break;
                default: break;
            }
            ui_style.SelectedIndex = 0;
        }

        #endregion

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;
            Hide();
        }

    }
}
